<template>
    <div>
        <h1>新增页面</h1>
    </div>
    <table class="table">
        <thead>
            <tr>
                <td>序号</td>
                <td>
                    <input type="text" v-model="data.stareRongName">
                </td>
            </tr>

              <tr>
                <td>时间</td>
                <td>
                        <input type="date" v-model="data.stareRongTime">
                </td>
            </tr>

              <tr>
                <td>手机号</td>
                <td>
                    <input type="text" v-model="data.phone">
                </td>
            </tr>

              <tr>
                <td>姓名</td>
                <td>
                    <input type="text" v-model="data.name">
                </td>
            </tr>

              <tr>
                <td>图片</td>
                <td>
                    <input type="file" @change="selectm">
                    <img style="height:60px;width:60px;" :src="axios.defaults.baseURL+data.stareRongImg">
                </td>
            </tr>

           <tr>
                <td>地址</td>
                <td>
                    <input type="text" v-model="data.adds">
                </td>
            </tr>

            <tr>
                <td>房型</td>
                <td>
                    <select v-model="data.stareID">
                        <option value="0">==请选择房型==</option>
                        <option v-for="a in obj":value="a.stareID">{{a.stareName}}</option>
                    </select>
                </td>
            </tr>

            <tr>
                <td></td>
                <td>
                    <input type="button" value="新增" @click="add()">
                </td>
            </tr>
        </thead>
    </table>
</template>

<script setup lang="ts">
 import axios from 'axios';
 import {ref,onMounted} from 'vue';
  import {useRouter} from 'vue-router';
 const router=useRouter();

  onMounted(()=>{
    GetStares();
  })

   const obj=ref({
      "stareID": 0,
      "stareName": "",

   })

  
   const selectm=(ad:any)=>{
     
       let f=ad.target.files[0]
       let fs=new FormData();
     fs.append("file",f);

      

        axios.post("http://localhost:5183/api/Upoad/Uploa",fs).then(res=>{
        data.value.stareRongImg=res.data;
        })

   }


   const GetStares=()=>{
    axios.get("http://localhost:5183/api/Stare/GetStares").then(res=>{

          obj.value=res.data

    })

   }

 
  const add=()=>{
    axios.post("http://localhost:5183/api/StareRong/AddAnync",data.value).then(res=>{
         if(res.data>0){
   alert("新增成功")
     router.push("/show")
         }else{
               alert("新增失败")
         }
    })
  }



   const data=ref({
     "stareRongId": 0,
  "stareRongName": "",
  "stareRongTime": "",
  "phone": "",
  "name": "",
  "stareRongImg": "string",
  "adds": "",
  "stareID": 0,
  "isdelete": 0
  
   })


</script>

<style scoped>

</style>    